<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreatePickupPointApplicationsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('ims_yz_pickup_point_applications', function (Blueprint $table) {
            $table->id();
            
            // 关联门店
            $table->unsignedBigInteger('store_id')->comment('申请门店ID');
            
            // 申请状态
            $table->enum('status', ['pending', 'approved', 'rejected'])
                  ->default('pending')
                  ->comment('申请状态：pending-待审核，approved-审核通过，rejected-审核不通过');
            
            // 审核信息
            $table->text('reason')->nullable()->comment('审核原因/备注');
            $table->unsignedBigInteger('reviewer_id')->nullable()->comment('审核人ID');
            $table->timestamp('reviewed_at')->nullable()->comment('审核时间');
            $table->timestamp('submitted_at')->nullable()->comment('提交时间');
            
            // Laravel 标准时间戳
            $table->timestamps(); // created_at & updated_at
            $table->softDeletes(); // deleted_at
            
            // 索引
            $table->index('store_id');
            $table->index('status');
            $table->index('submitted_at');
            $table->index('reviewed_at');
            $table->index(['status', 'submitted_at']);
            $table->index(['store_id', 'status']);
            
            // 外键约束
            $table->foreign('store_id')->references('id')->on('ims_yz_store')->onDelete('cascade');
            // $table->foreign('reviewer_id')->references('id')->on('admin_users');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('pickup_point_applications');
    }
}